import Vue from 'vue';
import Router from 'vue-router';
import Index from '@/modules/index';
import Login from '@/modules/login';
import Message from '@/modules/message';

Vue.use(Router);

// 路由懒加载
const LazyLoading = () => import('@/modules/lazyLoading');
const Methods = () => import('@/modules/methods');

export default new Router({
  // mode: 'history',
  routes: [
    {
      path: '/',
      name: 'index',
      component: Index,
      // beforeLeave: (to, from, next) => {
      beforeEnter: (to, from, next) => {
        console.log('路由独享守卫');
        console.log(to);
        console.log(from);
        next();
      }
    }, {
      path: '/login',
      name: 'login',
      component: Login
    }, {
      path: '/message',
      name: 'message',
      component: Message,
      meta: {
        isLogin: true
      }
    }, {
      path: '/lazyLoading',
      name: 'lazyLoading',
      component: LazyLoading, // component: resolve => require(['@/modules/lazyLoading'], resolve) 异步写法
      meta: {
        isLogin: false
      }
    }, {
      path: '/methods',
      name: 'methods',
      component: Methods, // component: resolve => require(['@/modules/lazyLoading'], resolve) 异步写法
      meta: {
        isLogin: false
      }
    }
  ]
});
